package com.maxmlr.music.admin.controller;

import com.maxmlr.music.admin.param.MenuParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import com.maxmlr.music.admin.service.MenuService;
import com.maxmlr.music.admin.entity.Menu;
import io.swagger.annotations.*;

import java.io.Serializable;

/**
 * @author max
 * @version 1.0
 * @ClassName AdminMenuController
 * @Description 菜单管理 页面跳转控制器
 * @Copyright Copyright (c) 2020: www.maxmlr.com.
 * @since 2020-06-14
 */
@Slf4j
@Controller
@Api(value = "/admin/menu", tags = "Menu 页面跳转控制器")
@RequestMapping("/admin/menu")
public class AdmMenuController {

    @Autowired
    public MenuService service;

    /**
     *  功能列表主页
     *
     * @return string
     */
    @GetMapping
    @RequiresPermissions("admin:menu:menu")
    public String menu() {
        return "admin/menu/menu";
    }

    /**
     *  添加页面
     *
     * @return string
     */
    @GetMapping("/add/{parentId}")
    @RequiresPermissions("admin:menu:add")
    public String add(@PathVariable("parentId") Integer parentId, Model model){
        Menu menu = service.getById(parentId);
        model.addAttribute("menu", menu);
        return "admin/menu/add";
    }

    /**
     *  编辑页面
     *
     * @return string
     */
    @GetMapping("/edit/{id}")
    @RequiresPermissions("admin:menu:edit")
    public String edit(@PathVariable("id") Integer id, Model model) {
        MenuParam param = service.getMenu(id);
        model.addAttribute("menu", param);
        return "admin/menu/edit";
    }


}
